package org.example.rabbitmqdemo.listener;

import com.rabbitmq.client.Channel;
import org.example.rabbitmqdemo.constant.Constants;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class WorkListener {
    @RabbitListener(queues = Constants.WORK_QUEUE)
    public void listenerQueue1(Message message, Channel channel) throws IOException {
        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        try{
            System.out.println("listener1 : " + message);
            int a = 3 / 0;
            channel.basicAck(deliveryTag, false);
        } catch (Exception e) {
            channel.basicNack(deliveryTag, false, true);
        }
    }

//    @RabbitListener(queues = Constants.WORK_QUEUE)
//    public void listenerQueue2(Message message){
//        System.out.println("listener2 : " + message);
//    }
}
